package com.testingedu.action.background;

import com.testingedu.action.background.RequestContext;
import com.testingedu.jdbcDao.TRegistDao;
import com.testingedu.model.TRegist;

public class TRegistAction extends RequestContext{
	
	private static final long serialVersionUID = -3982568379581852049L;
	private TRegist tRegist;
	private static TRegistDao tRegistDao = new TRegistDao();
	public TRegist gettRegist() {
		return tRegist;
	}
	public void settRegist(TRegist tRegist) {
		this.tRegist = tRegist;
	}
	
	public void _list() throws Exception {
		String url = request.getParameter("url");
		if ("info".equals(url)) {
			this.info(url);
		} else {
		createQueryResult();
		tRegistDao.list(queryResult, tRegist);
		request.setAttribute("queryResult", queryResult);
		request.getRequestDispatcher("/WEB-INF/admin/jsp/regist/list.jsp")
				.forward(request, response);
		}
	}
	public void _delete() throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		tRegistDao.delete(id);
		response.sendRedirect("/testingedu2/admin/regist/list");
	}
	
	private void info(String url) throws Exception {
		tRegist = tRegistDao.info(tRegist.getId());
		request.setAttribute("tRegist", tRegist);
		request.getRequestDispatcher("/WEB-INF/admin/jsp/regist/" + url + ".jsp")
				.forward(request, response);
	}
}
